﻿using MediatR;
using T.Materials.Domain.Model;
using T.Materials.Read.API.ApplicationRead.Command.ApprovalRecordCommand;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.Read.API.ApplicationRead.CommandHandler.ApprovalRecordCommandHandler
{
    public class MaterialRequisitionApprovalRecordCommandHandler : IRequestHandler<MaterialRequisitionApprovalRecordCommand, List<MApproval>>
    {
        private readonly IMApprow _happroval;

        public MaterialRequisitionApprovalRecordCommandHandler(IMApprow happroval)
        {
            _happroval = happroval;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<MApproval>> Handle(MaterialRequisitionApprovalRecordCommand request, CancellationToken cancellationToken)
        {
            return await _happroval.GetAsync(d => !d.IsDeleted && d.CompanyID == request.CompanyID && d.MaterialRequisitionId == request.MaterialRequisitionId);
        }
    }
}
